//
//  WLMUserAccount.swift
//  WeiBo
//
//  Created by Eric on 2017-01-07.
//  Copyright © 2017 Eric. All rights reserved.
//

import UIKit

class WLMUserAccount: NSObject,NSCoding {
    
    //设置模型属性
    var access_token: String?
    
    //生命周期
    var expires_date: Date?
    var expires_in : Double = 0 {
        didSet {
            //根据当前日期计算过期日期
            expires_date = Date(timeIntervalSinceNow: expires_in)
        }
    }
    
    //UID
    var uid: String?
    
    //用户昵称
    var screen_name: String?
    
    //用户头像地址,像素为180x180
    var avatar_large: String?
    
    //kvc
    init(dict:[String : Any]) {
        super.init()
        setValuesForKeys(dict)
    }
    
    //过滤
    override func setValue(_ value: Any?, forUndefinedKey key: String) {}
    
    ///实现协议方法
    
    //归档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey : "access_token")
        aCoder.encode(expires_date, forKey : "expires_date")
        aCoder.encode(uid, forKey : "uid")
        aCoder.encode(screen_name, forKey : "screen_name")
        aCoder.encode(avatar_large, forKey : "avatar_large")
    }
    
    //解档
    required init?(coder aDecoder: NSCoder) {
        //给属性赋值
        self.access_token = aDecoder.decodeObject(forKey:"access_token") as? String
        self.expires_date = aDecoder.decodeObject(forKey:"expires_date") as? Date
        self.uid = aDecoder.decodeObject(forKey:"uid") as? String
        self.screen_name = aDecoder.decodeObject(forKey:"screen_name") as? String
        self.avatar_large = aDecoder.decodeObject(forKey:"avatar_large") as? String
    }
    
    
    

}
